home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15033 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: cph-2.news.DK.net!dkuug!dknet!usenet
  2. From: jesk@dk-online.dk (Jes R. Klinke)
  3. Newsgroups: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
  4. Subject: Re: typecasting preferences
  5. Date: Tue, 16 Apr 1996 19:51:26 GMT
  6. Organization: Customer at DKnet
  7. Message-ID: <3173fb39.0@193.89.47.9>
  8. References: <4l020g$i9j@srvr1.engin.umich.edu>
  9. NNTP-Posting-Host: h9.dk-online.dk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM) wrote:
  13.  
  14. >Hi guys! I think my earlier post got lost so here it is again.... This is
  15. >for a student compiler project of mine.... 
  16.  
  17. >If you have a choice, do you want the parethesis pair over the caster
  18. >(C-style) or over the castee (Pascal-style)? eg...
  19.  
  20. >int a;
  21. >float b;
  22.  
  23. >a = (int)b; /* cast to int */
  24. >a = int(b); /* allowable in C++ */
  25.  
  26. >...as for Pascal...
  27. >a := integer(b); { "a" in an integer and "b" is a real }
  28.  
  29. >Thanx!
  30.  
  31. Hi,
  32. I like the pascal version because you can easily see what you are
  33. actually typecasting e.g.
  34.  
  35. a := 10000; b := 10000;
  36. c := longint(a * b);     { Bad, overflow occurs before typecast }
  37. c := longint(a) * b;     { Good, typecast then multiply }
  38.  
  39. I don't know how you distinguish between these cases in C++ (I have
  40. never done any serious programming in C).
  41.         Jes R Klinke
  42.  
  43.